import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import './api/mock'
import 'element-ui/lib/theme-chalk/index.css';
import './assets/less/index.less'
import Cookies from 'js-cookie'


Vue.config.productionTip = false
Vue.use(ElementUI);
//添加全局前置导航守卫
router.beforeEach((to,from,next)=>{
  //判断token是否存在
  const token=Cookies.get('token')
  //不存在token
  if(!token&&to.name!=='login')
  {
    next({name:'login'})
  }else if(token&&to.name==='login')
  {
    next({name:'home`'})
  }else{
    next()
  }
})
new Vue({
  router,
  store,
  created(){
    store.commit('addMeun',router)
  },
  render: h => h(App),
}).$mount('#app')
